package com.example.makerspace.config;

import com.example.makerspace.interceptor.AdminAudiInterceptor;
import com.example.makerspace.interceptor.AdminInterceptor;
import com.example.makerspace.interceptor.AuditInterceptor;
import com.example.makerspace.interceptor.LoginInterceptor;
import com.example.makerspace.utils.FileUtils;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SpringBootConfiguration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/api/application/**", "/api/coalition/addContact", "/api/coalition/contactDetail")
                .excludePathPatterns("/api/application/detailProduct");
        registry.addInterceptor(new AdminInterceptor())
                .addPathPatterns("/api/manger/deleteUser","/api/manger/editUserList","/api/manger/resetPassword","/api/manger/addUser","/api/manger/updateUserState","/api/manger/assignPermissions","/api/manger/forcedOffline"
                ,"/api/manger/getNewBulletin","/api/manger/addBulletin","/api/manger/updateNewBulletin","/api/manger/deleteNewBulletin");
        registry.addInterceptor(new AdminInterceptor())
                .addPathPatterns("/api/area/create", "/api/area/delete", "/api/area/update","/api/area/delete");
        registry.addInterceptor(new AdminInterceptor())
                .addPathPatterns("/api/task/create", "/api/task/delete", "/api/task/update","/api/task/delete","/api/task/follow","/api/task/cancelFollow");
        registry.addInterceptor(new AdminAudiInterceptor())
                .addPathPatterns("/api/manger/showUserList","/api/manger/onlineUser",
                        "/api/manger/userRegistration","/api/manger/showProducts","/api/manger/entRealName","/api/manger/questionsRegistration","/api/manger/otherShow","/api/manger/showUserOperate",
                        "/api/manger/pointSort","/api/manger/showTableData","/api/audit/*");
    }

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // /static/**是静态映射， file:static是文件在服务器的路径
        registry.addResourceHandler(FileUtils.staticUrl)
                .addResourceLocations(FileUtils.staticFile);
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
